package com.example.mybatisplusdemo.util;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.example.mybatisplusdemo.model.query.PageQuery;

/**
 * @author Xu Haidong
 * @date 2018/3/29
 */
public class PageUtils {

    private PageUtils() {
    }

    public static Page pageQueryToPage(PageQuery pageQuery){
        Page page;
        if (StringUtils.isNotEmpty(pageQuery.getOrderByField())) {
            if (null != pageQuery.getAsc()) {
                page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize(), pageQuery.getOrderByField(), pageQuery.getAsc());
            } else {
                page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize(), pageQuery.getOrderByField());
            }
        } else {
            page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
        }
        return page;
    }
}
